<?php namespace sacvoyage\proxy;

require_once 'sacvoyage/proxy/Collection.php';

use \sacvoyage\http\Browser;

require_once 'sacvoyage/http/util.php';
//use \sacvoyage\http\joad_json;
//use \sacvoyage\http\save_json;

class Resource {
	
	public function __construct($url, $user=null, $password=null) {
		$this->_browser=new Browser();
		if($user && $password) {
			$this->_browser->post($url, array(
				'user'=>$user, 'password'=>$password
			));
			$this->_url=rtrim($url, '/').'/'.$user;
			// TODO: check status
		} else {
			$this->_url=$url;
		}
	}
	
	public function getOwner() {
		return null;
	}
	
	public function getApplicationNames() {
		return null;
	}
	
	public function getApplication($name) {
		return null;
	}
	
	public function getCollectionNames() {
		$response=$this->_browser->request('GET', $this->_url."/*");
		return \sacvoyage\http\load_json(
			$response['body']
		);
	}
	
	public function getCollection($name) {
		return new Collection(
			$this->_browser, 
			rtrim($this->_url, '/').'/'.$name
		);
	}
	
	private $_browser, $_url;
}


?>
